<?php
// +----------------------------------------------------------------------
// | @filename PermissionController.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-10-29 18:29:23
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Controllers;


use Addons\Backend\Http\Requests\Permission\CreatePermissionRequest;
use Addons\Backend\Http\Requests\Permission\UpdatePermissionRequest;
use Addons\Backend\Logics\PermissionLogic;
use Illuminate\Http\Request;

class PermissionController extends BaseController
{
    protected $permissionLogic;

    public function __construct(PermissionLogic $permissionLogic)
    {
        $this->permissionLogic = $permissionLogic;
    }

    /**
     * 权限列表
     * @param Request $request
     * @return mixed
     */
    public function list(Request $request)
    {
        $res = $this->permissionLogic->list($request->input());
        return $this->respond($res);
    }


    /**
     * 所有权限
     * @return mixed
     */
    public function all()
    {
        $res = $this->permissionLogic->all();
        return $this->respond($res);
    }

    /**
     * 角色权限
     * @param Request $request
     * @return mixed
     */
    public function rolePermissions(Request $request){
        $res = $this->permissionLogic->rolePermissions($request->get('roleId'));
        return $this->respond($res);
    }

    /**
     * 创建权限
     * @param CreatePermissionRequest $request
     * @return mixed
     */
    public function create(CreatePermissionRequest $request){
        $res = $this->permissionLogic->create($request->validated());
        return $this->respond($res);
    }

    /**
     * 编辑权限
     * @param UpdatePermissionRequest $request
     * @return mixed
     */
    public function update(UpdatePermissionRequest $request){
        $res = $this->permissionLogic->update($request->validated());
        return $this->respond($res);
    }

    /**
     * 删除权限
     * @param $id
     * @return mixed
     */
    public function delete($id){
        $res = $this->permissionLogic->delete($id);
        return $this->respond($res);
    }
}
